﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TSTPCT : ViewBase
    {
        #region ==dwTPCT===========
        public static readonly DependencyProperty dwTPCTProperty = DependencyProperty.Register("dwTPCT",
            typeof(DataRow), typeof(TSTPCT),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwTPCTChanged));
        public DataRow dwTPCT
        {
            get
            {
                return (DataRow)GetValue(dwTPCTProperty);
            }
            set
            {
                SetValue(dwTPCTProperty, value);
            }
        }
        private static void OdwTPCTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TSTPCT;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwTPCT = row; 
            }
        }
        #endregion  
        #region ==PCT===========
        public static readonly DependencyProperty PCTProperty = DependencyProperty.Register("PCT",
            typeof(string), typeof(TSTPCT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPCTChanged));
        public string PCT
        {
            get
            {
                return (string)GetValue(PCTProperty);
            }
            set
            {
                SetValue(PCTProperty, value);
            }
        }
        private static void OnPCTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TSTPCT;
            if (src != null)
            {
                src.PCT = (string)e.NewValue;
                src.Load();
            }
        }
        #endregion
        public TSTPCT()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_PCTYPE(); 
            IsMasterFromMV = true;
            TBMain = MV.SetProd.Tables[TB];
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwTPCT = dwMaster;
            if (dwTPCT != null)
            {
               
            }
        }
        DataSet SResult;
        DataRow dwData;
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if(IsLoaded)
                return;
            base.Window_Loaded(sender, e);
            Load();
        }
        public void Locate()
        {

        } 

        public void Load()
        { 
            dwData = TBMain.NewRow();
            dwData["MANDANT"] = app.Mandant; 
            SResult = ((VICC_PCTYPE)MV).QueryICC_PCTYPE(dwData, 4);
            MergeData(SResult, false,true);
            foreach (DataRow row in TBMain.Rows)
            {
                row["DES"] = Helpers.Helper.GetGB2312Value(row["PCDES"].ToString());
            }
        } 
    }
}
